package com.cupk.common;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * 名称Result
 * 描述通用返回类对象，最终服务器都会封装成此类对象
 *
 * @version 1.0
 * @author:XiongRuiKai
 * @datatime:2023-06-11 10:52
 */
@Data
public class Result<T> {
        private Integer code; //编码：1成功，0和其它数字为失败

        private String msg; //错误信息

        private T data; //数据
//        private Integer total;

    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result() {
    }

    public static <T> Result<T> success(T object, String msg) {
            Result<T> r = new Result<T>();
            r.data = object;
            r.code = 1;
            r.msg = msg;
//            r.total = total;
            return r;
        }

        public static <T> Result<T> error(String msg) {
            Result r = new Result();
            r.msg = msg;
            r.code = 0;
            return r;
        }
 }

